#ifndef __Client__
#define __Client__

#include "..\server\command.h"
#include "IRegClient.h"
#include "keystate.h"

class Client
{
public:
    Client():m_bError(false),m_loggedin(false),m_registered(false){}

public:
    bool Initialize(PBasicInformation pInfo);
    void SetUsername(string user) {m_user = user;}
    void SetPassword(string pass) {m_pass = pass;}
    void SetHardwareID(string hwid) {m_hwid = hwid;}
    void SetProductKey(string pkey) {m_pkey = pkey;}
    void SetEmailAddress(string mail) {m_mail = mail;}
    void SetLoggedIn(){m_loggedin = true;m_registered = true;}
    void SetLoggedOff(){m_loggedin = false;m_registered = false;}
    bool IsExpired(){return m_keyinfo.state == expired;}

    bool GetLoggedIn(){return m_loggedin;}
    bool GetRegistered(){return m_registered;}
    void GetUsername(string& user) {user = m_user;}
    void GetPassword(string& pass) {pass = m_pass;}
    void GetHardwareID(string& hwid) {hwid = m_hwid;}
    void GetProductKey(string& pkey) {pkey = m_pkey;}
    void GetEmailAddress(string& mail) {mail = m_mail;}
    void UpdateRegistrationInfo(const PServerResponse pRes);

    time_t GetRegTime() {return m_keyinfo.register_time;}
    time_t GetDuration(){return m_keyinfo.duration;}
    time_t GetGenTime() {return m_keyinfo.generate_time;}
    int    GetClientType() {return m_keyinfo.client_type;}

    // command data
    bool GetRegistrationData(PServerCommand pData, int nSize);
    int  GetChangePasswordData(PServerCommand pSC,const string new_password);
    bool GetHeartBeatData(PServerCommand, int nSize);
    int  GetUnBindData(PServerCommand pData);
    bool GetLoginData( PServerCommand pData, int nSize );

private:

    bool StringSecurityCheck(const string s);
    bool MakeGeneralData(PGeneralRequest pGR);
    void Clear()
    {
        m_mail = "";
        m_user = "";
        m_hwid = "";
        m_pkey = "";
        m_pass = "";
        memset(&m_keyinfo, '\0', sizeof(ProductKeyInfo));
    }

    string m_user;
    string m_pass;
    string m_hwid;
    string m_pkey;
    string m_mail;
    bool m_bError;
    int  m_lasterror;
    bool m_registered;
    bool m_loggedin;
    ProductKeyInfo m_keyinfo;
};

#endif